package lxh.com.union.logic_business.model.net;

import com.google.gson.Gson;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import lxh.com.union.logic_business.model.bean.BaseBean;
import lxh.com.union.logic_business.model.bean.LoginBean;
import lxh.com.union.logic_business.util.ToastUtils;

/**
 * Created by Administrator on 2017/12/18.
 */

public class MyCallBack<T> extends StringCallback {
    private INetCallBack mINetCallBack;
    private Class<T> classOfT;
    public MyCallBack(Class<T> cls,INetCallBack INetCallBack) {
        mINetCallBack = INetCallBack;
        classOfT=cls;
    }

    @Override
    public void onSuccess(Response<String> response) {
        Gson gson = new Gson();
        BaseBean baseBean = gson.fromJson(response.body(), BaseBean.class);
        if (baseBean.hasSuccRes()) {
          mINetCallBack.success(gson.fromJson(response.body(),classOfT));
        } else {
           mINetCallBack.failed(baseBean.getMessage());
        }

    }

    @Override
    public void onError(Response<String> response) {
        super.onError(response);
        mINetCallBack.failed(response.getException());
    }
}
